cc.Class({
    extends: cc.Component,

    properties: {
        // foo: {
        //    default: null,
        //    url: cc.Texture2D,  // optional, default is typeof default
        //    serializable: true, // optional, default is true
        //    visible: true,      // optional, default is true
        //    displayName: 'Foo', // optional
        //    readonly: false,    // optional, default is false
        // },
        // ...
        _difenxuanze: null,
        _zimo: null,
        _wanfaxuanze: null,
        _zuidafanshu: null,
        _jushuxuanze: null,
        _dianganghua: null,
        _leixingxuanze: null,
    },

    // use this for initialization
    onLoad: function () {
        this._leixingxuanze = [];
        var t = this.node.getChildByName("leixingxuanze");
        for (var i = 0; i < t.childrenCount; ++i) {
            var n = t.children[i].getComponent("RadioButton");
            if (n != null) {
                this._leixingxuanze.push(n);
            }
        }

        // this._difenxuanze = [];
        // var t = this.node.getChildByName("difenxuanze");
        // for (var i = 0; i < t.childrenCount; ++i) {
        //     var n = t.children[i].getComponent("RadioButton");
        //     if (n != null) {
        //         this._difenxuanze.push(n);
        //     }
        // }
        // //console.log(this._difenxuanze);

        // this._zimo = [];
        // var t = this.node.getChildByName("zimojiacheng");
        // for (var i = 0; i < t.childrenCount; ++i) {
        //     var n = t.children[i].getComponent("RadioButton");
        //     if (n != null) {
        //         this._zimo.push(n);
        //     }
        // }
        // //console.log(this._zimo);

        // this._wanfaxuanze = [];
        // var t = this.node.getChildByName("wanfaxuanze");
        // for (var i = 0; i < t.childrenCount; ++i) {
        //     var n = t.children[i].getComponent("CheckBox");
        //     if (n != null) {
        //         this._wanfaxuanze.push(n);
        //     }
        // }
        // //console.log(this._wanfaxuanze);

        // this._zuidafanshu = [];
        // var t = this.node.getChildByName("zuidafanshu");
        // for (var i = 0; i < t.childrenCount; ++i) {
        //     var n = t.children[i].getComponent("RadioButton");
        //     if (n != null) {
        //         this._zuidafanshu.push(n);
        //     }
        // }
        // //console.log(this._zuidafanshu);

        this._jushuxuanze = [];
        var t = this.node.getChildByName("xuanzejushu");
        for (var i = 0; i < t.childrenCount; ++i) {
            var n = t.children[i].getComponent("RadioButton");
            if (n != null) {
                this._jushuxuanze.push(n);
            }
        }

        // this._dianganghua = [];
        // var t = this.node.getChildByName("dianganghua");
        // for (var i = 0; i < t.childrenCount; ++i) {
        //     var n = t.children[i].getComponent("RadioButton");
        //     if (n != null) {
        //         this._dianganghua.push(n);
        //     }
        // }
        //console.log(this._jushuxuanze);
    },

    onBtnBack: function () {
        this.node.active = false;
    },

    onBtnOK: function () {
        this.node.active = false;
        this.createRoom();
    },

    createRoom: function () {
        var self = this;
        var onCreate = function (ret) {
            console.log(ret)
            if (ret.errcode !== 0) {
                cc.vv.wc.hide();
                //console.log(ret.errmsg);
                if (ret.errcode == 2222) {
                    cc.vv.alert.show("房豆不足，创建房间失败!");
                }
                else {
                    cc.vv.alert.show("创建房间失败,错误码:" + ret.errcode);
                }
            }
            else {
                cc.vv.net.send('jumpOutHall', { userid: cc.vv.userMgr.userId })
                cc.vv.gameNetMgr.connectGameServer(ret, 'game');
            }
        };

        var type = 0;
        for (var i = 0; i < self._leixingxuanze.length; ++i) {
            if (self._leixingxuanze[i].checked) {
                type = i;
                break;
            }
        }

        if (type == 0) {
            type = "mj";
        } else if (type == 1) {
            type = "nn";
        } else if (type == 2) {
            type = "jdb";
        }

        var jushuxuanze = 0;
        for (var i = 0; i < self._jushuxuanze.length; ++i) {
            if (self._jushuxuanze[i].checked) {
                jushuxuanze = i;
                break;
            }
        }

        var data = {
            account: cc.vv.userMgr.account,
            sign: cc.vv.userMgr.sign,
            sex: cc.vv.userMgr.sex,
            icon: cc.vv.userMgr.headimg,
            conf: JSON.stringify({ type: type, jushuxuanze: jushuxuanze }),
            server: 'game'
        };
        // console.log(data);
        cc.vv.wc.show("正在创建房间");
        cc.vv.http.sendRequest("/create_private_room", data, onCreate);
    }

    // called every frame, uncomment this function to activate update callback
    // update: function (dt) {

    // },
});
